<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
    
  <meta name="description" content="love it" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    在hexo主题中为“分类”添加jstree插件 |  loveits
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
	  
  
<link rel="stylesheet" href="/css/main.css">

  
<link rel="stylesheet" href="/css/obsidian.css">

  
  <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
  
  
  
<link rel="stylesheet" href="//cdn.bootcss.com/codemirror/5.48.4/codemirror.min.css">

  
<link rel="stylesheet" href="//cdn.bootcss.com/codemirror/5.48.4/theme/dracula.css">

  
<link rel="stylesheet" href="//cdn.datatables.net/1.10.15/css/jquery.dataTables.css">

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" />
  

  

</head>

</html>

<body>
  <div id="app">
  <main class="content">
  <section class="outer">
  <article id="post-hexo/hexo-tree" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  在hexo主题中为“分类”添加jstree插件  
</h1>
  

    </header>
    
    
	
    
    <div class="article-meta">
      <a href="/p/7fb5a95e.html" class="article-date">
  <time datetime="2020-04-06T06:34:53.000Z" itemprop="datePublished">2020-04-06</time>
</a>
      <a href="#" class="article-updated">
  2020-12-16
</a>
      
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E5%A4%A7%E5%89%8D%E7%AB%AF/">大前端</a> / <a class="article-category-link" href="/categories/%E5%A4%A7%E5%89%8D%E7%AB%AF/hexo/">hexo</a>
  </div>

      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">1.6k字</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">8分钟</span>
        </span>
    </span>
</div>

      
    </div>
    
    
    <blockquote class="excerpt">
	<span id="excerpt"></span>
</blockquote>

<script src='https://cdn.jsdelivr.net/npm/typed.js@2.0.11/lib/typed.min.js'></script>

<script>
	try {
		var typed = new Typed("#excerpt", {
			strings: ['千里之行，始于足下。——老子', '浪费时间是一桩大罪过。——卢梭', '学习永远不晚。——高尔基'],
			startDelay: 0,
			typeSpeed: 100,
			loop: true,
			backSpeed: 120,
			showCursor: true
		});
	} catch (err) {

	}

</script>

    
    

    
    <div class="sidebar-right">
	<!-- <div class="box">
		<ul>
		<li><a href="/">36 <p>文章</p></a></li>
		<li><a href="/categories">16 <p>分类</p></a></li>
		<li><a href="/tags">26 <p>标签</p></a></li>
		</ul>
	</div> -->
	
	    <div class="tocbot"></div>
	
</div>




    
    
    

    <div class="article-entry" itemprop="articleBody">
      
      
      <h2 id="一丶需求"><a href="#一丶需求" class="headerlink" title="一丶需求"></a>一丶需求</h2><p>　　在hexo生成的博客文章中,使用tree,树形结构展示所有的分类以及分类下的所有文章标题。非常喜欢这样的展现方式，<br>可以非常直观的看到博客中的所有文章。  </p>
<p>经过简单的技术选型之后选择使用<code>jstree</code>这样一个经典jquery插件,<a href="https://www.jstree.com.cn/docs/json.html" target="_blank" rel="noopener">jstree中文网</a>，网站国内访问非常的快速，代码也是开源的，所有的功能都可以满足我的需求。</p>
<h2 id="二丶准备"><a href="#二丶准备" class="headerlink" title="二丶准备"></a>二丶准备</h2><p>在hexo的主题中，发现很少有人开发类似功能，在<a href="https://yelog.org/" target="_blank" rel="noopener">叶落阁</a>这个博客网站中，我看到类似的功能，不过研究了源码之后发现<code>作者可能</code>是先展示所有的文章，通过隐藏和展示来控制目录结构的变化，这样就不大好借鉴了😂。</p>
<p>大概看了20来个主题之后，发现大多数<code>分类</code>的实现方式都是官方提供的<code>list-categories</code>这个辅助函数上，通过修改对应的样式来实现自身需求。 <a href="https://hexo.io/zh-cn/docs/helpers#list-categories" target="_blank" rel="noopener">hexo-辅助函数</a>，官方文档有相对详细的介绍。</p>
<pre><code class="categories.ejs">&lt;%- list_categories({show_count: theme.show_count,depth:3}) %&gt;</code></pre>
<p>以上的代码就可以实现一个简单的分类页面，树形的分类目录，但是没有具体的文章标题。</p>
<a id="more"></a>
<h2 id="三丶着手开发"><a href="#三丶着手开发" class="headerlink" title="三丶着手开发"></a>三丶着手开发</h2><p>想要偷懒借鉴的想法泡汤了，还是自己开发吧。</p>
<h3 id="1丶简单使用jstree"><a href="#1丶简单使用jstree" class="headerlink" title="1丶简单使用jstree"></a>1丶简单使用jstree</h3><p>使用cdn的方式，引用对应的css，jquery，jstree</p>
<pre><code class="js">&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css&quot; /&gt;
&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js&quot;&gt;&lt;/script&gt;</code></pre>
<p>对应js文件引用成功之后,就可以简单使用了。  </p>
<p>在使用过程中，jstree支持2种json方案。</p>
<pre><code class="jstree-json-1.js?hide=1">  $(&#39;#jstree_demo_div&#39;).jstree({
    &#39;core&#39;: {
      &#39;data&#39;: [{
        &quot;id&quot;: &quot;21&quot;,
        &quot;parent&quot;: &quot;11&quot;,
        &quot;text&quot;: &quot;git&quot;,
        &quot;length&quot;: 3,
      }, {
        &quot;id&quot;: &quot;22&quot;,
        &quot;parent&quot;: &quot;11&quot;,
        &quot;text&quot;: &quot;hexo&quot;,
        &quot;length&quot;: 1
      }, {
        &quot;id&quot;: &quot;11&quot;,
        &quot;parent&quot;: &quot;#&quot;,
        &quot;text&quot;: &quot;前端&quot;,
        &quot;length&quot;: 1
      }, {
        &quot;id&quot;: &quot;12&quot;,
        &quot;parent&quot;: &quot;#&quot;,
        &quot;text&quot;: &quot;后端&quot;,
        &quot;length&quot;: 1
      }, {
        &quot;id&quot;: &quot;31&quot;,
        &quot;parent&quot;: &quot;21&quot;,
        &quot;text&quot;: &quot;gitee&quot;,
        &quot;length&quot;: 1
      }]

    }
  });</code></pre>
<p>这2中json中，有一点非常重要：<code>parent</code>和<code>children</code>是不能同时存在的。如果存在会报错：</p>
<pre><code class="js">Uncaught TypeError: Cannot read property &#39;id&#39; of undefined
    at parse_flat (dda70c6a-a4f2-4cfc-a5c9-be4f467dbacd:19)
    at parse_flat (dda70c6a-a4f2-4cfc-a5c9-be4f467dbacd:87)
    at self.onmessage (dda70c6a-a4f2-4cfc-a5c9-be4f467dbacd:232)</code></pre>
<pre><code class="jstree-json-2.js?hide=1">  $(&#39;#jstree_demo_div&#39;).jstree({
    &#39;core&#39;: {
      &#39;data&#39;: [{
        &quot;id&quot;: &quot;11&quot;,
        &quot;pid&quot;: &quot;#&quot;,
        &quot;text&quot;: &quot;前端&quot;,
        &quot;length&quot;: 1,
        &quot;children&quot;: [{
          &quot;id&quot;: &quot;21&quot;,
          &quot;pid&quot;: &quot;11&quot;,
          &quot;text&quot;: &quot;git&quot;,
          &quot;length&quot;: 3,
          &quot;children&quot;: [{
            &quot;id&quot;: &quot;31&quot;,
            &quot;pid&quot;: &quot;21&quot;,
            &quot;text&quot;: &quot;gitee&quot;,
            &quot;length&quot;: 1
          }]
        }, {
          &quot;id&quot;: &quot;22&quot;,
          &quot;pid&quot;: &quot;11&quot;,
          &quot;text&quot;: &quot;hexo&quot;,
          &quot;length&quot;: 1
        }]
      }, {
        &quot;id&quot;: &quot;12&quot;,
        &quot;pid&quot;: &quot;#&quot;,
        &quot;text&quot;: &quot;后端&quot;,
        &quot;length&quot;: 1
      }]

    }
  });</code></pre>
<p>这2中格式的json都可以实现下面的效果。<br><img src="hexo-tree/1.jpg" alt="hexo-tree">  </p>
<ul>
<li><input disabled="" type="checkbox"> TODO之后写一篇jstree的源码精读篇</li>
</ul>
<h3 id="2丶数据转换"><a href="#2丶数据转换" class="headerlink" title="2丶数据转换"></a>2丶数据转换</h3><p>hexo变量中的<code>site.categories</code>可以拿到站点中所有分类的数据，包含所有分类下的所有文章。 </p>
<p><code>typeof site.categories</code>是<code>object</code>,但是<code>JSON.stringify(site.categories)</code>会报错，好像这个对象并不是JSON格式，输出的格式如下：<br><img src="hexo-tree/2.jpg" alt="site.categories Object"></p>
<ul>
<li><input checked="" disabled="" type="checkbox"> TODO这里应该是一个js实例，但是实例对象不可以使用JSON.stringify吗？可以研究一下。  </li>
</ul>
<p>这个对象虽然不是标准的JSON，但是大部分JSON方法都可以直接使用。</p>
<pre><code class="categories.ejs?hide=1">&lt;script type=&quot;text/javascript&quot;&gt;
   var categoriesArr = [];
   site.categories.sort(&#39;name&#39;).each(function(item,i){ 
     let obj = {}
     obj.id = item._id;
     obj.pid = item.parent ?item.parent:&quot;#&quot;;
     obj.text = item.name;
     let postArr = [];
     item.posts.each(function(post,i){
       let postObj = {};
       postObj.text = post.title;
       postObj.icon = &quot;jstree-file&quot;;
       postObj.a_attr = {&quot;href&quot;:&quot;../&quot;+post.canonical_path}
       postArr.push(postObj)
     })
     obj.children  = postArr;
     categoriesArr.push(obj);
   });
    var oData = transData(categoriesArr, &#39;id&#39;, &#39;pid&#39;, &#39;children&#39;)
    //转化数据格式
  function transData(a, idStr, pidStr, chindrenStr) {
        var r = [],
            hash = {},
            id = idStr,
            pid = pidStr,
            children = chindrenStr,
            i = 0,
            j = 0,
            len = a.length;
        for (; i &lt; len; i++) {
            hash[a[i][id]] = a[i];
        }
        for (; j &lt; len; j++) {
            var aVal = a[j],
                hashVP = hash[aVal[pid]];
            if (hashVP) {
                !hashVP[children] &amp;&amp; (hashVP[children] = []);
                hashVP[children].push(aVal);
            } else {
                r.push(aVal);
            }
        }
        return r;
    }
&lt;/script&gt;</code></pre>
<h3 id="3丶创建jstree实例"><a href="#3丶创建jstree实例" class="headerlink" title="3丶创建jstree实例"></a>3丶创建jstree实例</h3><p>在<code>script</code>标签中可以使用<code>&lt;%- oData %&gt;</code>获得<code>ejs</code>中的变量的string，注意得到的值是<code>ejs变量.toString()</code>，这个要注意一下，例如数组的toString就不是<code>[1,2]</code>而是<code>1,2</code>，所以建议使用<code>&lt;%- JSON.stringify(oData) %&gt;</code>来获取值。</p>
<pre><code class="js">&lt;script type=&quot;text/javascript&quot;&gt;
  var cateArr = &lt;%- JSON.stringify(oData) %&gt;
  $(&#39;#cateTree&#39;).jstree({
      &quot;animation&quot;: 0,
      &#39;core&#39;: {
          &#39;data&#39;: cateArr
      },
   &#39;state&#39;: {
         &quot;opened&quot;:true,
    },
    &#39;plugins&#39;: [&quot;search&quot;, &quot;types&quot;, &quot;wholerow&quot;, &quot;state&quot;]
  })
  //双击跳转到对应的文章页面
  .on(
      &#39;dblclick.jstree&#39;,
      function(event, data) {
          let $target = event.target;
        console.log($target)
          window.location.href = $target.href; 
      });
&lt;/script&gt;</code></pre>
<h3 id="4丶完整代码"><a href="#4丶完整代码" class="headerlink" title="4丶完整代码"></a>4丶完整代码</h3><pre><code class="categories.ejs?hide=1">&lt;section class=&quot;outer&quot;&gt;
&lt;h1 class=&quot;page-type-title&quot;&gt;&lt;%= __(&#39;categories&#39;) %&gt;&lt;/h1&gt;

 &lt;div id=&quot;cateTree&quot;&gt;&lt;/div&gt;
&lt;/section&gt;

&lt;% 
  var categoriesArr = [];
  site.categories.sort(&#39;name&#39;).each(function(item,i){ 
    let obj = {}
    obj.id = item._id;
    obj.pid = item.parent ?item.parent:&quot;#&quot;;
    obj.text = item.name;
    let postArr = [];
    item.posts.each(function(post,i){
      let postObj = {};
      postObj.text = post.title;
      postObj.icon = &quot;jstree-file&quot;;
      postObj.a_attr = {&quot;href&quot;:&quot;../&quot;+post.canonical_path}
      postArr.push(postObj)
    })
    obj.children  = postArr;
    categoriesArr.push(obj);
  });

    var oData = transData(categoriesArr, &#39;id&#39;, &#39;pid&#39;, &#39;children&#39;)

    function transData(a, idStr, pidStr, chindrenStr) {
        var r = [],
            hash = {},
            id = idStr,
            pid = pidStr,
            children = chindrenStr,
            i = 0,
            j = 0,
            len = a.length;
        for (; i &lt; len; i++) {
            hash[a[i][id]] = a[i];
        }
        for (; j &lt; len; j++) {
            var aVal = a[j],
                hashVP = hash[aVal[pid]];
            if (hashVP) {
                !hashVP[children] &amp;&amp; (hashVP[children] = []);
                hashVP[children].push(aVal);
            } else {
                r.push(aVal);
            }
        }
        return r;
    }


%&gt;
&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js&quot;&gt;&lt;/script&gt;

&lt;script type=&quot;text/javascript&quot;&gt;
  var cateArr = &lt;%- JSON.stringify(oData) %&gt;
  $(&#39;#cateTree&#39;).jstree({
      &quot;animation&quot;: 0,
      &#39;core&#39;: {
          &#39;data&#39;: cateArr
      },
   &#39;state&#39;: {
         &quot;opened&quot;:true,
    },
    &#39;plugins&#39;: [&quot;search&quot;, &quot;types&quot;, &quot;wholerow&quot;, &quot;state&quot;]
  })
  .on(
      &#39;dblclick.jstree&#39;,
      function(event, data) {
          let $target = event.target;
        console.log($target)
          window.location.href = $target.href; 
      });
&lt;/script&gt;</code></pre>
<h2 id="👀-待优化"><a href="#👀-待优化" class="headerlink" title="👀 待优化"></a>👀 待优化</h2><ol>
<li>在ejs文件中直接引入<code>jquery</code>和<code>jstree</code> </li>
<li>数据量大的时候，是否还是通过json string的时候方式来创建jstree实例</li>
</ol>

     
      
    </div>

    

    <!-- copyright -->
    
    <br>
    <hr>
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>版权声明：</strong>
          自由转载-非商用-禁止演绎-保持署名
          （<a href="http://creativecommons.org/licenses/by-nc-nd/4.0/deed.zh" target="_blank" rel="noopener">CC BY-NC-ND 4.0</a>）
        </li>
        <li>
          <i class="ri-links-fill"></i>
          <strong>原文链接：</strong>
          <a href="http://loveits.cn/p/7fb5a95e.html " title="在hexo主题中为“分类”添加jstree插件 ">http://loveits.cn/p/7fb5a95e.html</a>
        </li>
      </ul>
    </div>


    
    <footer class="article-footer">
      
      
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://loveits.cn/p/7fb5a95e.html" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/blog/" rel="tag">blog</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/hexo/" rel="tag">hexo</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/jstree/" rel="tag">jstree</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/p/67f51b7d.html" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            vlog计划
          
        </div>
      </a>
    
    
      <a href="/p/f2c18b67.html" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">emoji表情库</div>
      </a>
    
  </nav>


  

  

  
  
<div class="gitalk" id="gitalk-container"></div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1.6.2/dist/gitalk.css">


<script src="https://cdn.jsdelivr.net/npm/gitalk@1.6.2/dist/gitalk.min.js"></script>


<script src="https://cdn.jsdelivr.net/npm/blueimp-md5@2.10.0/js/md5.min.js"></script>

<script type="text/javascript">
  var gitalk = new Gitalk({
    clientID: '09248ac3809d34e5aed0',
    clientSecret: '01a391e5c9fcc0e1b791dddfdbff490583cf878d',
    repo: 'gitalk',
    owner: 'loyalvi',
    admin: ['loyalvi'],
    // id: location.pathname,      // Ensure uniqueness and length less than 50
    //id: md5(location.pathname),
	id: location.pathname,
    distractionFreeMode: false,  // Facebook-like distraction free mode
    pagerDirection: 'last'
  })
	
  gitalk.render('gitalk-container')
</script>

  

</article>
</section>
  <footer class="footer">
  <div class="outer">
    <ul class="list-inline">
      <li>
        <!-- loveits blog α -->
        &copy;
        2020
        loyalvi α
      </li>
	  <li>
	    
	    Powered by
	    
	    
	    <a href="https://hexo.io" target="_blank">Hexo</a> Theme <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
	    
	  </li>
      <!-- <li>
        联系方式（TODO）
      </li> -->
    </ul>
    <ul class="list-inline">
      <li>
        
      </li>
	  
	  
	  <li>
	    <a href="http://www.beian.miit.gov.cn/" target="_black">苏ICP备20008261号-1</a>
	  </li>
	  
	  
      <li>
        <!-- cnzz统计 -->
        
      </li>
	  
    </ul>
  </div>
</footer>
  <div class="to_top">
  <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>
  </div>
  </main>
  <aside class="sidebar">
  <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/logo-white.png" alt="loveits"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories/%E8%AE%A1%E5%88%92/">计划</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories/%E5%AD%97%E5%85%B8/">字典</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/todo">待办</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/p/9ff79b23.html">我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div> 
  </aside>
  <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
  
  
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/share.js"></script>


<script src="/js/lazyload.min.js"></script>


<script src="/js/jquery.nicescroll.min.js"></script>

<script type="text/javascript" charset="utf8" src="http://cdn.datatables.net/1.10.15/js/jquery.dataTables.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>

<script>
  try {
    var typed = new Typed("#subtitle", {
      strings: ['loveits blog', '中意他的博客', ''],
      startDelay: 0,
      typeSpeed: 100,
      loop: true,
      backSpeed: 100,
      showCursor: true
    });

  } catch (err) {
  }

</script>

<script>
//var nice = $("main").niceScroll();
	$('table').DataTable({
		"language": {
			"lengthMenu": "每页 _MENU_ 条记录",
			"zeroRecords": "没有找到记录",
			"info": "",
			"infoEmpty": "无记录",
			"infoFiltered": "(从 _MAX_ 条记录过滤)",
			"search":"搜索:"
		},
		"paging": false,
		searching: false,
		"columnDefs" : [ 
			{
			targets: [0],
			render: function(data, type, row, meta) {
				return  (meta.row + 1);
			}
			}],
        "order": [[4, 'asc']]	
	});			
</script>






<script src="/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: "auto",
    onClick: (e) => {
      $('.toc-link').removeClass('is-active-link');
      $(`a[href=${e.target.hash}]`).addClass('is-active-link');
      $(e.target.hash).scrollIntoView();
      return false;
    }
  });
</script>

<script src="https://cdn.bootcss.com/codemirror/5.48.4/codemirror.min.js"></script>

    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/javascript/javascript.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/css/css.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/xml/xml.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/shell/shell.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/python/python.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/htmlmixed/htmlmixed.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/htmlembedded/htmlembedded.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/clike/clike.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/php/php.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/powershell/powershell.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/yaml/yaml.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/addon/mode/multiplex.min.js"></script>



<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/js/ayer.js"></script>



<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>




<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>
	
  
  </div>
</body>

</html>